<template>
    <div id="lightbox">
        <div class="title">
            <li v-for="(i, index) in header" :key="index">
                {{ i }}
            </li>
        </div>
        <div
            id="real"
            ref="real"
            :class="{ anim: animate == true }"
            @mouseenter="mEnter"
            @mouseleave="mLeave"
        >
            <li v-for="(item, index) in realist" :key="index">
                <p>
                    {{ item.name }}
                </p>
                <p>
                    {{ item.gender === 1 ? "男" : gender == 2 ? "女" : "其他" }}
                </p>
                <p>
                    {{ item.age }}
                </p>
                <p>
                    {{ item.locationName }}
                </p>
                <p>
                    {{ item.address }}
                </p>
                <p>
                    {{ item.collectionTime }}
                </p>
            </li>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        realist: {
            type: Array,
            default: () => []
        }
    },
    data () {
        return {
            animate: false,
            header: ["姓名", "性别", "年龄", "采集点", "采集地点", "采集时间"]
        };
    },
    mounted () {
        this.timer1 = setInterval(this.scroll, 1000);
    },
    methods: {
        scroll () {
            var that = this;
            if (that.realist.length > 5) {
                that.$refs.real.style.marginTop = "-30px";
                that.animate = !that.animate;
            }
            setTimeout(function () {
                that.realist.push(that.realist[0]);
                that.realist.shift();
                if (that.realist.length > 5) {
                    that.$refs.real.style.marginTop = "0px";
                    that.animate = !that.animate;
                }
            }, 500);
        },
        mEnter () {
            clearInterval(this.timer1);
        },
        mLeave () {
            this.timer1 = setInterval(this.scroll, 1000);
        }
    }
};
</script>
<style scoped>
* {
    margin: 0;
    padding: 0;
}

#lightbox {
    width: 100%;
    height: 150px;
    line-height: 30px;
    overflow: hidden;
    border-radius: 14px;
    transition: all 0.5s;
}
.title {
    width: 100%;
    height: 30px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    display: flex;
    position: relative;
    z-index: 9999;
    background: #163ea6;
}
.title li {
    width: 20.7%;
    text-align: center;
}
.title li:nth-child(1)  {
    width: 16.6%;
    text-align: center;
}
.title li:nth-child(2)  {
    width: 10.6%;
    text-align: center;
}
.title li:nth-child(3)  {
    width: 10.6%;
    text-align: center;
}
.anim {
    transition: all 0.5s;
}
#real {
    width: 100%;
    z-index: 99;
}
#real li {
    width: 100%;
    list-style: none;
    line-height: 30px;
    height: 30px;
    z-index: 1;
    display: flex;
    border-bottom: 1px dashed #163ea6;
}
#real li p {
    width: 20.7%;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    text-align: center;
}
#real li p:nth-child(1) {
    width: 16.6%;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    text-align: center;
}
#real li p:nth-child(2) {
    width: 10.6%;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    text-align: center;
}
#real li p:nth-child(3) {
    width: 10.6%;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    text-align: center;
}
</style>
